package com.aizhixin.lab.company.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.company.domain.SystemSetDomain;
import com.aizhixin.lab.company.service.SystemSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/base/systemset")
@Api(value = "系统设置相关API")
public class SystemSetController {
	@Autowired
	private AccountService accountService;
	@Autowired
	private SystemSetService systemSetService;

	
	@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod = "POST", value = "保存系统设置", response = Void.class, notes = "保存系统设置<br>@author zhengning")
	public ResponseEntity<?> saveInfor(@RequestHeader("Authorization") String token,
			 @RequestBody SystemSetDomain dto) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
		
		Map<String, Object> result = systemSetService.save(dto);
		return new ResponseEntity(result, HttpStatus.OK);
	}


	@RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod = "GET", value = "查询系统设置", response = Void.class, notes = "查询系统设置<br>@author zhengning")
	public ResponseEntity<?> getInfor(@RequestHeader("Authorization") String token) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
		Map<String, Object> result = systemSetService.getInfor();
		return new ResponseEntity(result, HttpStatus.OK);
	}


}
